package com.example.its2021606134chh.LifeIndexModule;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.its2021606134chh.R;

/**
 * @ClassName: IndexUI$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 2021/6/21$
 * @Version: 1.0
 */
public class IndexUI extends LinearLayout {
    LinearLayout layout;
    ImageView imageView;
    TextView tvIndexName,tvLevel,tvAlert;
    Context context;
    public IndexUI(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        LayoutInflater.from(context).inflate(R.layout.index_layout,this,true);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        layout=findViewById(R.id.customLayout);
        imageView=findViewById(R.id.imgDMVCar1);
        tvIndexName=findViewById(R.id.tvIndexName);
        tvLevel=findViewById(R.id.tvLevel);
        tvAlert=findViewById(R.id.tvAlert);
    }

    public void setImageView(int resID) {
        imageView.setImageResource(resID);
    }

    public void setTvIndexName(String indexName) {
        tvIndexName.setText(indexName);
    }

    public void setTvLevel(String level) {
        tvLevel.setText(level);
    }

    public void setTvAlert(String alert) {
        tvAlert.setText(alert);
    }

    public void setThresholdAndReality(int threshold,int reality) {
        if(reality > threshold) {//实际值大于阈值
             layout.setBackgroundColor(Color.parseColor("#FF0000"));
        }else{
            layout.setBackgroundColor(Color.parseColor("#87CEFA"));
        }
    }
}
